package com.itcoon.system.security;/**
 * @author Athric Yu
 * 2025/1/6
 **/

import com.itcoon.cloud.framework.security.model.UserPrincipal;
import com.itcoon.cloud.framework.security.service.AbstractUserDetailsService;
import com.itcoon.cloud.framework.security.service.IUserPrincipalAdvice;
import com.itcoon.system.entity.AdminUserDO;
import com.itcoon.system.service.AdminUserService;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

/**
 *
 *
 * @author Athric Yu
 * 2025/1/6
 **/
@Component
public class AdminUserUserDetailsService extends AbstractUserDetailsService {

    private final AdminUserService userService;

    public AdminUserUserDetailsService(List<IUserPrincipalAdvice> principalAdvices, AdminUserService userService) {
        super(principalAdvices);
        this.userService = userService;
    }

    @Override
    public UserPrincipal queryUser(String username) {
        AdminUserDO user = userService.getOne(AdminUserDO::getUsername, username);
        return user == null ? null : new AdminUserPrincipal(user.getId(), user.getUsername(), user.getPassword(), true, true, true, true, Collections.emptyList());
    }
}
